<?php
/* -----------------------------------------------------------------
* 	ID:						$Id: product_reviews.php 2 2011-02-17 13:35:25Z akausch $
* 	Letzter Stand:			$Revision: 2 $
* 	zuletzt geändert von: 	$Author: akausch $
* 	Datum:					$Date: 2011-02-17 14:35:25 +0100 (Do, 17. Feb 2011) $
*
* 	commerce:SEO by Webdesign Erfurt
* 	http://www.commerce-seo.de
*
* 	Copyright (c) since 2010 commerce:SEO
* ------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* --------------------------------------------------------------- */

$module_smarty = new Smarty;
$module_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');

require_once (DIR_FS_INC.'xtc_row_number_format.inc.php');
require_once (DIR_FS_INC.'xtc_date_short.inc.php');
include(FILENAME_DISPLAY_VVCODES);

$info_smarty->assign('options', $products_options_data);

$name_query = xtc_db_fetch_array(xtDBquery("SELECT customers_firstname, customers_lastname FROM ".TABLE_CUSTOMERS." WHERE customers_id = '".(int) $_SESSION['customer_id']."'"));

if($name_query['customers_firstname'] == '')
	$name = TEXT_GUEST;
else
	$name = $name_query['customers_firstname'].' '.$name_query['customers_lastname'];
	
$module_smarty->assign('AUTHOR', $name);

$reviews_query = xtDBquery("SELECT (avg(reviews_rating) / 5 * 100) as average_rating FROM " . TABLE_REVIEWS . " WHERE products_id = '" . $product->data['products_id'] . "'");
$reviews = xtc_db_fetch_array($reviews_query);
   
$module_smarty->assign('AVERAGE','&Oslash; '.number_format($reviews['average_rating'], 2).'%');
if($_SESSION['success_msg'] !='') {
	$module_smarty->assign('SUCCESS_MSG', $_SESSION['success_msg']);
	unset($_SESSION['success_msg']);
	$module_smarty->assign('JS_REVIEW', '<script type="text/javascript">jQuery(document).ready(function(){jQuery("#product_reviews_write").hide();});</script>');
	
} elseif($_SESSION['error_msg'] !='') {
	$module_smarty->assign('ERROR_MSG', $_SESSION['error_msg']);
	unset($_SESSION['error_msg']);
} else 
	$module_smarty->assign('JS_REVIEW', '<script type="text/javascript">jQuery(document).ready(function(){jQuery("#product_reviews_write").hide();});</script>');
		
if ($_SESSION['customers_status']['customers_status_write_reviews'] != 0) 
{
	if((SITE_OVERLAYS == 'true') && (isset($_GET['overlay']))) {
		$module_smarty->assign('BUTTON_WRITE', TEXT_WRITE_REVIEW . '<a href="'.xtc_href_link(FILENAME_PRODUCT_REVIEWS_WRITE,'products_id='.$product->data['products_id'].'&'.$overlay_link).'" class="overlay_link_reviews">'.xtc_image_button('button_write_review.gif', IMAGE_BUTTON_WRITE_REVIEW,'style="cursor:pointer"').'</a>');
	} else {
		$module_smarty->assign('BUTTON_WRITE', TEXT_WRITE_REVIEW . '<a href="javascript:void(0)">'.xtc_image_button('button_write_review.gif', IMAGE_BUTTON_WRITE_REVIEW,'style="cursor:pointer"').'</a>');
	}
	$module_smarty->assign('FORM_ACTION_REVIEW', xtc_draw_form('product_reviews_write', xtc_href_link(FILENAME_PRODUCT_REVIEWS_WRITE, 'action=process&mode=ajax&'.xtc_product_link($product->data['products_id'],$product->data['products_name']).'#rev'), 'POST', 'onsubmit="return checkForm();"'));
	$vv_validation=true;

	$module_smarty->assign("CaptchaDescription", CAPTCHA_DESCRIPTION);
	$module_smarty->assign('VVIMG', '<img src="'.$vvimg.'" alt="Captcha" />'); 
	$module_smarty->assign('INPUT_CODE', xtc_draw_input_field('stringCaptcha', '', 'size="6" maxlength="6"', 'text', false));
	$module_smarty->assign('CodeCaptcha', xtc_draw_hidden_field('codeCaptcha', $_SESSION["vvcode"], ''));
	
	$module_smarty->assign('INPUT_TEXT', xtc_draw_textarea_field('review', 'soft', 60, 15, $_SESSION['tmp_review'], 'style="width:99.9%"', false));
	$module_smarty->assign('INPUT_RATING', xtc_draw_radio_field('rating', '1','','class="star"').' '.xtc_draw_radio_field('rating', '2','','class="star"').' '.xtc_draw_radio_field('rating', '3','','class="star"').' '.xtc_draw_radio_field('rating', '4','','class="star"').' '.xtc_draw_radio_field('rating', '5','','class="star"'));
	$module_smarty->assign('BUTTON_SUBMIT', xtc_image_submit('button_send.gif', IMAGE_BUTTON_SEND).xtc_draw_hidden_field('get_params', $get_params));
	$module_smarty->assign('FORM_END', '</form>');
}

if ($product->getReviewsCount() <= 0)
	$module_smarty->assign('NEW_REVIEW', true);
$module_smarty->assign('language', $_SESSION['language']);
$module_smarty->assign('module_content', $product->getReviews());
$module_smarty->caching = 0;
$module = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/products_reviews.html');
if ($_SESSION['customers_status']['customers_status_write_reviews'] != 0 || $_SESSION['customers_status']['customers_status_read_reviews'] != 0) {
	$info_smarty->assign('MODULE_products_reviews', $module);
}
?>